package com.auxgroup.hr.front.service.personnal.impl;

import com.auxgroup.hr.front.commons.utils.DateUtils;
import com.auxgroup.hr.front.dao.domain.PsContractData;
import com.auxgroup.hr.front.dao.domain.PsJob;
import com.auxgroup.hr.front.dao.repository.PsContractDataRepository;
import com.auxgroup.hr.front.dao.repository.PsJobcodeTblRepository;
import com.auxgroup.hr.front.service.personnal.ContractDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * Created by nitongqian on 2019/1/18.
 */
@Service("contractDataService")
public class ContractDataServiceImpl implements ContractDataService {

    private static final Logger logger = LoggerFactory.getLogger(ContractDataServiceImpl.class);

    @Autowired
    private PsContractDataRepository psContractDataRepository;
    @Override
    public List<PsContractData> findAll(String emplid) {
        return psContractDataRepository.findByEmplid(emplid);
    }

    @Override
    public Date getZhuanzhengDt(String emplid) {
        List<PsContractData> pcds = psContractDataRepository.findInterns(emplid);
        if(pcds.isEmpty()) {
            return null;
        }
        Date latestDate = DateUtils.parseDate("19000101", "YYYYMMDD");
        for(PsContractData pcd : pcds) {
            if(pcd.getRsInternEndDt() != null && pcd.getRsInternEndDt().compareTo(latestDate) > 0) {
                latestDate = pcd.getRsInternEndDt();
            }
        }
        return latestDate.equals(DateUtils.parseDate("19000101", "YYYYMMDD")) ? null : latestDate;
    }
}
